package model

import "gpt-api/framework/db"

// 提现账户
type CashAccount struct {
	db.BaseModel
	UserID  uint64 `json:"user_id" gorm:"column:user_id;type:int;not null;comment:用户ID"`
	Type    uint8  `json:"type" gorm:"column:type;type:int;not null;comment:收款类型，1微信，2支付宝，3银行卡"`
	Phone   string `json:"phone" gorm:"column:phone;type:varchar(50);default:'';comment:收款手机号"`
	Name    string `json:"name" gorm:"column:name;type:varchar(50);default:'';comment:收款人姓名"`
	Account string `json:"account" gorm:"column:account;type:varchar(50);default:'';comment:收款帐号"`
	Idcard  string `json:"idcard" gorm:"column:idcard;type:varchar(50);default:'';comment:身份证号"`
}

// 表名
func (CashAccount) TableName() string {
	return "cash_account"
}

// 根据ID获取提现账户
func (e CashAccount) GetById(database *db.DB, id uint64) (CashAccount, error) {
	var cashAccount CashAccount
	err := database.Model(&CashAccount{}).Where("id = ?", id).First(&cashAccount).Error
	return cashAccount, err
}

// 创建提现账户
func (e CashAccount) Create(database *db.DB) (uint64, error) {
	err := database.Create(&e).Error
	return e.ID, err
}

// 更新提现账户
func (e CashAccount) Update(database *db.DB) error {
	return database.Save(&e).Error
}

// 根据UserId获取提现账户
func (e CashAccount) GetCashAccountByUserId(database *db.DB, userId uint64) ([]CashAccount, error) {
	var list []CashAccount
	err := database.Model(&CashAccount{}).Where("user_id = ?", userId).Find(&list).Error
	return list, err
}
